package com.uit.project.bustrip.adapter;

import java.util.ArrayList;

import com.uit.project.bustrip.R;
import com.uit.project.bustrip.entity.Trip;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ListTripAdaper extends ArrayAdapter<Trip>{
	private ArrayList<Trip> items;
	private Activity context;
	public ListTripAdaper(Activity context, ArrayList<Trip> items) {
		super(context, R.layout.activity_home_item, items);
		this.items = items;
		this.context = context;
	}
	static class ViewHolder {
		protected TextView routeCode;
		protected TextView routeName;
		protected TextView driverName;
		protected TextView carName;
		protected TextView startTime;
	}
	/* (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final Trip item = items.get(position);
		View v = null;
		if (convertView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			v = inflater.inflate(R.layout.activity_home_item, null);
			final ViewHolder vh = new ViewHolder();
			vh.routeCode = (TextView) v.findViewById(R.id.routeCode);
			vh.routeName = (TextView) v.findViewById(R.id.routeName);
			vh.driverName = (TextView) v.findViewById(R.id.DriverName);
			vh.carName = (TextView) v.findViewById(R.id.carName);
			vh.startTime = (TextView) v.findViewById(R.id.starttime);
			v.setTag(vh);
		}
		else{
			v = convertView;
		}
		ViewHolder holder = (ViewHolder) v.getTag();
		holder.routeCode.setText(item.code);
		holder.routeName.setText(item.tripname);
		holder.driverName.setText(item.drivername);
		holder.carName.setText(item.carname);
		holder.startTime.setText(item.starttime);
		return v;
	}
}
